package org.abettor.angleworm.ui.widget;

import java.io.IOException;

import org.abettor.angleworm.i18n.Translator;
import org.abettor.util.Environment;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

/**
 * 最近联系历史页
 * @author abettor
 *
 */
public class HistoryComposite extends Composite
{
	private static Translator translator = null;
	private Display display = Display.getDefault();
	private Table tableHistory = null;

	/**
	 * 构造最近联系历史页
	 * @param parent
	 * @param style
	 */
	public HistoryComposite(Composite parent, int style)
	{
		super(parent, style);
		initialize();
	}

	private void initialize()
	{
		try
		{
			translator = Translator.getInstance();
			if(translator == null)
			{
				translator = Translator.initialize("en_US");
			}
		}
		catch (IOException e)
		{
			e.printStackTrace();
			return;
		}

		GridLayout gridLayout = new GridLayout();
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		gridLayout.verticalSpacing = 0;
		gridLayout.horizontalSpacing = 0;
		setLayout(gridLayout);

		showHistory();
	}

	private void showHistory()
	{
		GridData gridDataTable = new GridData();
		gridDataTable.grabExcessHorizontalSpace = true;
		gridDataTable.grabExcessVerticalSpace = true;
		gridDataTable.horizontalAlignment = GridData.FILL;
		gridDataTable.verticalAlignment = GridData.FILL;

		tableHistory = new Table(this, SWT.BORDER);
		tableHistory.setHeaderVisible(false);
		tableHistory.setLinesVisible(false);
		tableHistory.setLayoutData(gridDataTable);

		//TODO	显示历史列表
		for(int i = 0; i < 7; i ++)
		{
			TableItem ti = new TableItem(tableHistory, SWT.NONE);
			ti.setText("Record " + i);
			ti.setImage(new Image(display, Environment.getFilePath("img/avatar/none.png")));
		}
	}

}
